<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model backend\modules\home\models\Article */

$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => '文章列表', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$front_imgurl = Yii::$app->params['front_imgurl'];
?>
<style type="text/css">
    th{min-width:120px;}
</style>
<div class="article-view">

    <div class="box box-primary">
        <div class="box-header with-border">
            <h3 class="box-title">操作</h3>
        </div>
        <div class="box-body">
            <p>
                <?= Html::a('更新', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
                <?= Html::a('删除', ['delete', 'id' => $model->id], [
                    'class' => 'btn btn-danger',
                    'data' => [
                        'confirm' => 'Are you sure you want to delete this item?',
                        'method' => 'post',
                    ],
                ]) ?>

                <?= Html::a('附件上传 (支持文件格式.doc,.pdf)', ['upload-file', 'id' => $model->id], ['class' => 'btn btn-info']) ?>

            </p>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6">
            <div class="box box-solid box-primary">
                <div class="box-header">
                    <h3 class="box-title">详情</h3>
                </div>
                <div class="box-body">
                    <?= DetailView::widget([
                            'model' => $model,
                            'attributes' => [
                                'id',
                                'cid',
                                [
                                    'format' => 'raw',
                                    'attribute' => 'type',
                                    'value' => function($model) {
                                        if($model->type == 0){
                                            return '<span class="btn btn-xs btn-info">单页面</span>';
                                        } else {
                                            return '<span class="btn btn-xs btn-info">论文资源</span>';
                                        }
                                    },
                                ],
                                'title',
                                'summary',
                                'author',
                                'read',
                                'is_hot',
                                'is_recommend',
                                'tag',
                                'order',
                                'image_path',
                                'url:url',
                                'content:ntext',
                                [
                                    'format' => 'raw',
                                    'attribute' => 'status',
                                    'value' => function($model) {
                                        if($model->status == 0){
                                            return '<span class="btn btn-xs btn-danger">未发布</span>';
                                        } elseif ($model->status == 1) {
                                            return '<span class="btn btn-xs btn-success">已发布</span>';
                                        } else {
                                            return '';
                                        }

                                    },
                                ],
                                'publish_date',
                                [
                                    'format' => 'raw',
                                    'attribute' => 'create_time',
                                    'value' => function($model) {
                                       return date('Y-m-d H:i:s', $model->create_time);
                                    },
                                ],
                            ],
                        ])
                    ?>
                </div>
            </div>
        </div>
        <?php if($model->appendix){ ?>
        <div class="col-md-6">
            <div class="box box-solid box-primary">
                <div class="box-header">
                    <h3 class="box-title">附件</h3>
                </div>
                <div class="box-body">
                    <?php if(strstr($model->appendix, '.doc')){ ?>
                    <iframe src='https://view.officeapps.live.com/op/view.aspx?src=<?=$front_imgurl . $model->appendix?>' width='100%' height='500px' frameborder='1'>
                    </iframe>
                    <?php }else{ ?>
                        <iframe src="<?=$front_imgurl . $model->appendix?>" frameborder="0" scrolling="no" id="external-frame" onload="setIframeHeight(this)" style="width: 100%;height: 500px"></iframe>
                    <?php }?>
                </div>
            </div>
        </div>
        <?php }?>
        <div class="clearfix"></div>
    </div>




</div>
